﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Basic4Net.Utility.Common;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Base
{
    public partial class AppraisePage : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Appraisebind();
            }
        }

        private void Appraisebind()
        {
            this.rpt_Appraise.DataSource = (new BusinessRules.Appraise()).ListAll();
            this.rpt_Appraise.DataBind();
        }

        protected void rpt_Appraise_OnItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string msg = string.Empty;
            BusinessRules.Appraise bll = new BusinessRules.Appraise();
            switch (e.CommandName)
            {
                case "Change":
                    TextBox txt = (TextBox)e.Item.FindControl("txt_Name");
                    TextBox txtA = (TextBox)e.Item.FindControl("txt_Appraise");
                    Entities.t_Appraise model = new Entities.t_Appraise();
                    model.RID = int.Parse(e.CommandArgument.ToString());
                    model.AppraiseName = txt.Text;
                    double n = 0;
                    double.TryParse(txtA.Text,out n);
                    if (txtA.Text.Length > 0)
                    {
                        model.Appraise = n;
                    }

                    model.SchoolMark = "School";
                    bll.Update(model, ref msg);
                    break;
                case "Del":
                    bll.Delete(int.Parse(e.CommandArgument.ToString()), ref msg);
                    Appraisebind();
                    break;
            }
        }

        [System.Web.Services.WebMethod]
        protected void btnBind_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;
            Entities.t_Appraise model = new Entities.t_Appraise();
            model.AppraiseName = this.txt_TypeName.Text;
            double n = 0;
            double.TryParse( this.txt_TypeNameAppraise.Text, out n);
            if (this.txt_TypeNameAppraise.Text.Length > 0)
            {
                model.Appraise = n;
            }
            model.SchoolMark = SchoolMark;
            (new BusinessRules.Appraise()).Add(model, ref msg);
            Appraisebind();
        }
    }
}